package com.yaorange.module.system.mapper;

import com.yaorange.module.system.entity.dto.SysUserQueryDTO;
import com.yaorange.pojo.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SysUserMapper {

    List<SysUser> findAll(SysUserQueryDTO sysUserQueryDTO);

    @Insert("insert into sys_user(user_username,user_password,user_avatar,user_nickname,create_by,create_time,update_time,admin) values(#{userUsername},#{userPassword},#{userAvatar},#{userNickname},#{createBy},#{createTime},#{updateTime},#{admin})")
    void save(SysUser sysUser);

    @Select("select * from sys_user where user_id=#{id}")
    SysUser findById(Integer id);

    @Update("update sys_user set user_username=#{userUsername},user_password=#{userPassword},user_avatar = #{userAvatar},user_nickname=#{userNickname},update_time=#{updateTime},admin=#{admin} where user_id=#{userId}")
    void update(SysUser userDetails);

    @Delete("delete from sys_user where user_id=#{id}")
    void deleteById(Integer id);

    @Update("update sys_user set admin=#{admin} where user_id=#{id}")
    void updateAdmin(Long id,Integer admin);

    @Select("select * from sys_user where user_username = #{username}")
    SysUser findByUsername(String username);
}
